/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bill.view;

import bill.model.vo.Inventory;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import util.AppException;

/**
 *
 * @author Administrator
 */
public class InventoryEditor extends AbstractCellEditor
                         implements TableCellEditor,
			            ActionListener{
    JButton button;  
    protected static final String EDIT = "edit";
    public static final String EDIT_OVER = "edit_over";
    public static final String CLOSE = "close";
    private AddOrderDetailJDialog aod;
    Inventory inv = null;
    

    public InventoryEditor(java.awt.Frame parent, boolean modal) throws IOException, FileNotFoundException, AppException{
        button = new JButton();
        button.setActionCommand(EDIT);
        button.addActionListener(this);
        aod = new AddOrderDetailJDialog(button,parent,modal);
    }
    
    public Object getCellEditorValue() {
        return inv;
    }

    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
       return button;
    }

    public void actionPerformed(ActionEvent e) {
        String command = e.getActionCommand();
        if (EDIT.equals(command)) {
            try {
                aod.initData();
                aod.setVisible(true);
                fireEditingStopped();
            }catch (FileNotFoundException ex) {
                Logger.getLogger(InventoryEditor.class.getName()).log(Level.SEVERE, null, ex);
            }  catch (IOException ex) {
                Logger.getLogger(InventoryEditor.class.getName()).log(Level.SEVERE, null, ex);
            }  catch (AppException ex) {
                Logger.getLogger(InventoryEditor.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if(EDIT_OVER.equals(command)){
           inv = aod.getSelectedInventory();           
        } else if(CLOSE.equals(command)){
             cancelCellEditing();
        }
        button.setActionCommand(EDIT);
    }

}
